<template>
  <div class="w">
    <Row>
      <Col :span="11" :offset="2">
        <label for="">操作模块：</label>
        <span>{{currRow.title }} / </span><dict-tag  style="display: inline-block" :options="dict.type.sys_oper_type" :spanText="true" :value="currRow.businessType"/>
      </Col>
      <Col :span="11" :offset="0">
        <label for="">请求地址：</label>
        <span>{{currRow.operUrl}}</span>
      </Col>
    </Row>
    <Row>
      <Col :span="11" :offset="2">
        <label for="">登录信息：</label>
        <span>{{currRow.operName }} / {{currRow.operIp}} / {{currRow.operLocation}}</span>
      </Col>
      <Col :span="11" :offset="0">
        <label for="">请求方式：</label>
        <span>{{currRow.requestMethod}}</span>
      </Col>
    </Row>
    <Row>
      <Col :span="22" :offset="2">
        <label for="">操作方法：</label>
        <span>{{currRow.method}}</span>
      </Col>
    </Row>
    <Row>
      <Col :span="22" :offset="2">
        <label for="">请求参数：</label>
        <div style="margin-right: 80px; word-break:break-all;">
          {{currRow.operParam}}
        </div>
      </Col>
    </Row>
    <Row>
      <Col :span="22" :offset="2">
        <label for="">返回参数：</label>
        <span>{{currRow.jsonResult}}</span>
      </Col>
    </Row>
    <Row>
      <Col :span="11" :offset="2">
        <label for="">操作状态：</label>
        <dict-tag :options="dict.type.sys_common_status" :spanText="true" :value="currRow.status" style="display: inline-block"/>
      </Col>
      <Col :span="11" :offset="0">
        <label for="">操作时间：</label>
        <span>{{currRow.operTime}}</span>
      </Col>
    </Row>
    <div style="text-align: center; padding: 25px;">
      <Button style="width: 100px;" type="primary" @click="formValidate" disabled>提 交</Button>
      <Button style="width: 100px; margin-left: 20px;" @click="formCancel">取 消</Button>
    </div>
  </div>
</template>

<script>
import * as ruoyi from '@/utils/ruoyi'
import { addType, updateType } from "@/api/system/dict/type";
import { Message } from "@uni/vue";
export default {
  name: "app",
  dicts: ["sys_normal_disable","sys_common_status","sys_oper_type"],
  props: {
    id: {
      type: Number,
      default: 0
    },
    currRow: {
      default: () => {}
    },
    refData: {
      default: () => {}
    }
  },
  data() {
    return {
      form: {
        dictName: this.currRow.dictName,
        dictType: this.currRow.dictType,
        status: this.currRow.status?this.currRow.status:'0',
        remark: this.currRow.remark,
        dictId: this.currRow.dictId,
        createTime: this.currRow.createTime,
        createBy: this.currRow.createBy,
      },
      formRules: {
        dictNameRules: [{ required: true, message: "请输入字典名称" }],
        dictTypeRules: [{ required: true, message: "字典类型不能为空" }],
      },
      roleOptions: [],
      isModalVisible: false
    }
  },
  mounted() {
    // console.log("mounted id: ", this.id);
    // console.log("mounted currRow: ", this.currRow);
    // console.log("mounted refData: ", this.refData);
  },
  methods: {
    formValidate: function () {
      this.$refs.formRef.submit();
    },
    formCancel: function () {
      // this.$refs.formRef.reset();
      this.handleCancel();
    },
    formFinish: function (formValues) {
      this.form = formValues;
      this.formSubmit()
    },
    async formSubmit() {
      // 公共属性
      this.form.createBy = this.$store.state.user.name;
      this.form.createTime = ruoyi.parseTime(Date.now());
      this.form.updateBy = this.$store.state.user.name;
      this.form.updateTime = ruoyi.parseTime(Date.now());

      // 提交表单请求
      this.isModalVisible = false;
      let reqForm = JSON.parse(JSON.stringify(this.form));
      // console.log("reqForm: ", reqForm);
      if (this.id) {
        // 修改
        reqForm.dictId = this.id;
        const rs = await updateType(reqForm);
        if (rs.code !== 200) return Message.error({ text: '修改信息失败：' + rs.msg });
        Message.success({ text: '修改信息完成' });
        this.handleCancel();

      } else {
        // 新增
        const rs = await addType(reqForm);
        if (rs.code !== 200) return Message.error({ text: '新增信息失败：' + rs.msg });
        Message.success({ text: '新增信息完成' });
        this.handleCancel();
      }
    },
    handleCancel: function () {
      this.$emit('handleCancel');
    },
    selectOnChange(val) {
      this.modalValue = val;
    },
  }
}
</script>

<style scoped>
  .w {
    background-color: #F9FAFB;
  }

  /* 标题 */
  .title-area span {
    display: inline-block;
    font-weight: 500;
    line-height: 36px;
    margin-left: 15px;
  }
  label {
    margin: 20px 0;
    display: inline-block;
    font-weight: bold;
  }
</style>
